import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/index/Home";
import CompanyService from "../views/companyService/CompanyService";
import IntellectualProperty from "../views/intellectualProperty/IntellectualProperty";
import QualificationCertificate from "../views/qualificationCertificate/QualificationCertificate";
import LawHelp from "../views/lawHelp/LawHelp";
import LegalDocument from "../views/legalDocument/LegalDocument";
import SuccessfulCase from "../views/successfulCase/SuccessfulCase";
import Login from "../views/Login";
import Register from "../views/Register";
import Service from "../views/service/Service";
import Dowmload from "../views/legalDocument/childCpn/Dowmload";
import CustomMade from "../views/legalDocument/childCpn/CustomMade";
import Verify from "../views/legalDocument/childCpn/Verify";
import Server from "../views/server/Server";

import company from "./company";
import server from "./server";
import buyer from "./buyer"
import Purchaser from "../views/purchaser/Purchaser";
import Pay from "../views/Pay";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'Home',
    component: Home
  },

  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },
  {
    path: '/server',
    name: 'Server',
    component: Server,
    meta:{
      login : true
    },
    redirect: '/server/account',
    children: [
        ...server
    ]
  },
  {
    path: '/buyer',
    name: 'Buyer',
    component: Purchaser,
    meta:{
      login : true
    },
    redirect: '/buyer/account',
    children: [
      ...buyer
    ]
  },
  {
    path: '/service',
    name: 'Service',
    redirect:'/service/companyService',
    component: Service,
    children:[
      {
        path: 'companyService',
        name: 'CompanyService',
        redirect:'/service/companyService/companyBuild',
        component: CompanyService,
        children:[
            ...company
        ]
      },
      {
        path: 'intellectualProperty',
        name: 'IntellectualProperty',
        component: IntellectualProperty,
      },
      {
        path: 'qualificationCertificate',
        name: 'QualificationCertificate',
        component: QualificationCertificate
      },

      {
        path: 'lawHelp',
        name: 'LawHelp',
        component: LawHelp
      },
      {
        path: 'legalDocument',
        name: 'LegalDocument',
        component: LegalDocument,
        redirect: '/service/legalDocument/download',
        children:[
          {
            path: 'download',
            name: 'Download',
            component: Dowmload,
          },
          {
            path: 'customMade',
            name: 'CustomMade',
            component: CustomMade,
          },
          {
            path: 'verify',
            name: 'Verify',
            component: Verify,
          }]
      },
      {
        path: 'successfulCase',
        name: 'SuccessfulCase',
        component: SuccessfulCase
      },
    ]
  },
  {
    path: '/pay',
    name: 'Pay',
    component: Pay,
    meta: {
      login : true
    }
  }
]

const router = new VueRouter({
  routes,
  mode:'history'
})

//避免重复路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
